<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %><!-- 数据库操作需要 -->        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
		//获取参数，转换为相应的类型
		String RequestID=request.getParameter("RequestID");
		String staff=request.getParameter("staff");
		/*String Status=null;
		String AgreeOrNot=request.getParameter("AgreeOrNot");
		String CensorContent=request.getParameter("CensorContent");
		String Adminname=request.getParameter("Adminname");
		String AdminTime=request.getParameter("AdminTime");
		System.out.println(" RequestID:"+ RequestID+"AgreeOrNot:"+AgreeOrNot);
		if(AgreeOrNot.equals("同意"))
			Status="审核通过";
		else
			Status="审核未通过";*/
		String ID=null;
		//第一个java代码段查询数据
		try{
			Class.forName("org.h2.Driver");//加载驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return;
		}
		String url="jdbc:h2:d:/CompanyCar/temp/mydbtest";
		Connection conn=null;

	//数据库连接与查询过程中可能会引发sql异常
	try {
		//获取数据库连接(url,username,password)			
		conn = DriverManager.getConnection(url,"sa","");
		Statement stmt=null;//放在if或循环语句中，则只在语句段中有效
		ResultSet rs=null;//放在if或循环语句中，则只在语句段中有效
		//准备执行数据库插入，此处使用了?方式，比拼接字符串更清晰
		String sql1="delete from CarRequest where RequestID='"+RequestID+"'";
		String sql2="delete from EmployeeCarInfo_view where RequestID='"+RequestID+"'";
		String sql3="delete from Driver_Task where RequestID='"+RequestID+"'";
		stmt=conn.createStatement();
		//执行数据库查询，获取结果集
		int result=stmt.executeUpdate(sql1);
		result=stmt.executeUpdate(sql2);
		result=stmt.executeUpdate(sql3);
		//关闭表达式对象
		stmt.close();			
		//关闭数据库			
		conn.close();			
		
	} catch (SQLException e) {
		e.printStackTrace();
	} finally{
		//防止数据库未正常关闭
		try{
			if (conn!=null && (!conn.isClosed())){
				conn.close();
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

	request.setAttribute("addok","1");
	if(staff==null)
		request.getRequestDispatcher("/C-fail.jsp").forward(request,response);
	else
		request.getRequestDispatcher("/X-UseCar_Records.jsp").forward(request,response);
%>
</body>
</html>